package com.taobao.api.request;

import java.util.Map;

import com.taobao.api.ApiRuleException;
import com.taobao.api.TaobaoRequest;
import com.taobao.api.internal.util.RequestCheckUtils;
import com.taobao.api.internal.util.TaobaoHashMap;
import com.taobao.api.response.VideosSearchResponse;

/**
 * TOP API: taobao.videos.search request
 * 
 * @author auto create
 * @since 1.0, 2013-07-21 16:38:14
 */
public class VideosSearchRequest implements TaobaoRequest<VideosSearchResponse> {

  private Map<String, String> headerMap = new TaobaoHashMap();
  private TaobaoHashMap       udfParams;                      // add
                                                              // user-defined
                                                              // text parameters
  private Long                timestamp;

  /**
   * 页码。默认返回的数据是从第一页开始
   */
  private Long                currentPage;

  /**
   * 需要返回的视频对象字段。VideoItem结构体中所有字段均可返回；多个字段用“,”分隔；
   * 其中video_play_info中的播放url可选择性返回，其余属性全部返回；如果想返回整个子对象中所有url，
   * 那字段为video_play_info，如果是想返回子对象里面的字段，那字段为video_play_info.web_url。
   */
  private String              fields;

  /**
   * 关键字(标题or标签，不能同时设置title,tag，否则冲突)
   */
  private String              keywords;

  /**
   * 每页条数，默认值是12
   */
  private Long                pageSize;

  /**
   * 视频状态列表；视频状态：等待转码（1），转码中（2），转码失败（3），等待审核（4），未通过审核（5），通过审核（6）
   */
  private String              states;

  /**
   * 视频标签
   */
  private String              tag;

  /**
   * 视频标题
   */
  private String              title;

  /**
   * 视频上传者数字id
   */
  private Long                uploaderId;

  /**
   * 在淘宝视频中的应用key，该值向淘宝视频申请产生
   */
  private Long                videoAppKey;

  public void setCurrentPage(Long currentPage) {
    this.currentPage = currentPage;
  }

  public Long getCurrentPage() {
    return this.currentPage;
  }

  public void setFields(String fields) {
    this.fields = fields;
  }

  public String getFields() {
    return this.fields;
  }

  public void setKeywords(String keywords) {
    this.keywords = keywords;
  }

  public String getKeywords() {
    return this.keywords;
  }

  public void setPageSize(Long pageSize) {
    this.pageSize = pageSize;
  }

  public Long getPageSize() {
    return this.pageSize;
  }

  public void setStates(String states) {
    this.states = states;
  }

  public String getStates() {
    return this.states;
  }

  public void setTag(String tag) {
    this.tag = tag;
  }

  public String getTag() {
    return this.tag;
  }

  public void setTitle(String title) {
    this.title = title;
  }

  public String getTitle() {
    return this.title;
  }

  public void setUploaderId(Long uploaderId) {
    this.uploaderId = uploaderId;
  }

  public Long getUploaderId() {
    return this.uploaderId;
  }

  public void setVideoAppKey(Long videoAppKey) {
    this.videoAppKey = videoAppKey;
  }

  public Long getVideoAppKey() {
    return this.videoAppKey;
  }

  public Long getTimestamp() {
    return this.timestamp;
  }

  public void setTimestamp(Long timestamp) {
    this.timestamp = timestamp;
  }

  public String getApiMethodName() {
    return "taobao.videos.search";
  }

  public Map<String, String> getTextParams() {
    TaobaoHashMap txtParams = new TaobaoHashMap();
    txtParams.put("current_page", this.currentPage);
    txtParams.put("fields", this.fields);
    txtParams.put("keywords", this.keywords);
    txtParams.put("page_size", this.pageSize);
    txtParams.put("states", this.states);
    txtParams.put("tag", this.tag);
    txtParams.put("title", this.title);
    txtParams.put("uploader_id", this.uploaderId);
    txtParams.put("video_app_key", this.videoAppKey);
    if (this.udfParams != null) {
      txtParams.putAll(this.udfParams);
    }
    return txtParams;
  }

  public void putOtherTextParam(String key, String value) {
    if (this.udfParams == null) {
      this.udfParams = new TaobaoHashMap();
    }
    this.udfParams.put(key, value);
  }

  public Class<VideosSearchResponse> getResponseClass() {
    return VideosSearchResponse.class;
  }

  public void check() throws ApiRuleException {
    RequestCheckUtils.checkNotEmpty(fields, "fields");
    RequestCheckUtils.checkMaxListSize(states, 10, "states");
    RequestCheckUtils.checkMaxLength(tag, 256, "tag");
    RequestCheckUtils.checkMaxLength(title, 256, "title");
    RequestCheckUtils.checkNotEmpty(uploaderId, "uploaderId");
    RequestCheckUtils.checkNotEmpty(videoAppKey, "videoAppKey");
  }

  public Map<String, String> getHeaderMap() {
    return headerMap;
  }
}
